package com.lovo.util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;

public class Verifier {

    public static ResultTokenVo verifierJwt(String token){
        //私钥及加密算法
        Algorithm algorithm = Algorithm.HMAC256(CreateToken.TOKEN_SECRET);
        String info="";
        JWTVerifier verifier = JWT.require(algorithm).build();
     ResultTokenVo vo=new ResultTokenVo();
        try {
            DecodedJWT jwt = verifier.verify(token); //认证token
            info=jwt.getClaim("info").asString();//取token中的信息
           vo.setTag(1);
           vo.setJson(info);
        }catch (Exception e){
            vo.setTag(0);
        }
        return vo;
    }

    public static void main(String[] args) {
//     String token=   CreateToken.getToken("{'name':'赵云'}");
//        System.out.println(token);
    ResultTokenVo vo=    Verifier.verifierJwt("ey0J0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2ODU2OTAzMjMsImluZm8iOiJ7J25hbWUnOifotbXkupEnfSJ9.wFAsS1-cfCOFAGlo7HIO-y6X8LfyGr4fDP4Qb6Ij7_0");
        System.out.println(vo);
    }
}
